﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class slot : MonoBehaviour, IDropHandler
{
    public int id;
    private cardcontrol cardd;

    void Start()
    {
        cardd = GameObject.Find("cardmanager").GetComponent<cardcontrol>();
    }

    public void OnDrop(PointerEventData eventData)
    {
        carddata droppedcard = eventData.pointerDrag.GetComponent<carddata>();
        if (cardd.cards[id].Id == -1)
        {
            cardd.cards[droppedcard.slot] = new Card();
            cardd.cards[id] = droppedcard.card;
            droppedcard.slot = id;
        }
        else
        {
            Transform card = this.transform.GetChild(0);
            card.GetComponent<carddata>().slot = droppedcard.slot;
            card.transform.SetParent(cardd.slots[droppedcard.slot].transform);
            card.transform.position = cardd.slots[droppedcard.slot].transform.position;


            cardd.cards[droppedcard.slot] = card.GetComponent<carddata>().card;
            cardd.cards[id] = droppedcard.card;

            droppedcard.slot = id;
            droppedcard.transform.SetParent(this.transform);
            droppedcard.transform.position = this.transform.position;
        }
    }

}
